import { createStore } from "redux";
import { composeWithDevTools } from "@redux-devtools/extension";

// 引入定义好的 actionType 的常量
import { INC, DNC, INCBYNUM } from "./action-types";

const initialState = {
  count: 0,
};

function rootReducer(state = initialState, action: any) {
  switch (action.type) {
    case INC:
      return {
        ...state,
        count: state.count + 1,
      };
    case DNC:
      return {
        ...state,
        count: state.count - 1,
      };
    case INCBYNUM:
      return {
        ...state,
        count: state.count + action.payload,
      };
    default:
      return state;
  }
}

export default createStore(rootReducer, composeWithDevTools());
